package com.guigu.gulicommon.constant.enumes;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 线程池等待策略
 */
@AllArgsConstructor
@Getter
public enum ThreadPoolWaitPolicy {
    /**
     * 线程池满了，调用者放弃执行
     */
    CALLER_RUNS(1, new ThreadPoolExecutor.CallerRunsPolicy()),

    /**
     * 线程池满了，调用者抛出异常
     */
    ABORT(2, new ThreadPoolExecutor.AbortPolicy()),
    /**
     * 线程池满了，直接丢弃任务
     */
    DISCARD(3, new ThreadPoolExecutor.DiscardPolicy()),
    /**
     * 线程池满了，队列满了，直接丢弃任务
     */
    DISCARD_OLDEST(4, new ThreadPoolExecutor.DiscardOldestPolicy()),
    ;

    private final Integer policyCode;
    private final RejectedExecutionHandler policy;
}
